package Thread;

//创建线程
//方法二 继承Runnable类
class MyRunnable implements  Runnable{
    @Override
    public void run() {
        System.out.println("hello thread");
        try{
            Thread.sleep(1000);
        }catch(InterruptedException e){
            e.printStackTrace();
        }
    }
}
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = new MyRunnable();
        // 创建线程对象，并将 Runnable 对象传递给 Thread 构造函数
        Thread t = new Thread(runnable);//向上转型
        t.start();

        while (true){
            System.out.println("hello main");
            Thread.sleep(1000);
        }
    }
}
